package cn.lutu.lutu.controller;

import cn.lutu.lutu.mapper.CommentMapper;
import cn.lutu.lutu.pojo.dto.CommentPostDTO;
import cn.lutu.lutu.pojo.vo.CommentVO;
import cn.lutu.lutu.response.ResultVO;
import cn.lutu.lutu.security.CustomUserDetails;
import cn.lutu.lutu.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Api(tags = "评论模块")
@RestController
@RequestMapping("/ /v1/comments/")
public class CommentController {

    @Autowired
    CommentMapper mapper;
    @Autowired
    CommentService commentService;

    @ApiOperation("发表评论")
    @PostMapping("post")
    public ResultVO post(@RequestBody CommentPostDTO commentPostDTO, @AuthenticationPrincipal CustomUserDetails cud){
        mapper.insert(commentService.insert(commentPostDTO,cud));
        return ResultVO.ok();
    }


    @ApiOperation("获取评论数")
    @GetMapping("counts")
    public ResultVO selectCount(Long id){
        return ResultVO.ok(mapper.selectCount(id));
    }

    @ApiOperation("获取评论列表")
    @GetMapping("list")
    public ResultVO selectAll(){
        List<CommentVO> list = mapper.selectAll();
        return ResultVO.ok(list);
    }
}
